package com.zy.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.zy.dao.AdminDao;
import com.zy.entity.Admin;
import com.zy.entity.Course;
import com.zy.entity.Paging;
import com.zy.entity.Speaker;
import com.zy.entity.Subject;
import com.zy.entity.Video;
import com.zy.entity.VideoEx;
import com.zy.service.AdminService;
@Component
@Transactional
public class AdminServiceImpl implements AdminService{
	@Autowired
	private AdminDao ad;
	
	
	public AdminDao getAd() {
		return ad;
	}

	public void setAd(AdminDao ad) {
		this.ad = ad;
	}
	//登录
	@Override
	public boolean login(Admin an) {
		List<Admin> admin = ad.getAllAdmin();
		for (Admin admin2 : admin) {
			if(an.getUserName().trim().equals(admin2.getUserName())&&an.getPassword().trim().equals(admin2.getPassword())){
				return true;
			}
		}
		return false;
	}
	//查找所有视频
	@Override
	public List<Video> getAllVideo() {
		return ad.getAllVideo();
	}

	@Override
	public List<Speaker> getAllSpeaker() {
		return ad.getAllSpeaker();
	}
	//查询所有课程
	@Override
	public List<Course> getAllCourse() {
		return ad.getAllCourse();
	}
	//添加视频
	@Override
	public void addVideo(Video vd) {
		ad.addVideo(vd);
	}
	//批量删除
	@Override
	public void deleteBatcheVideo(int[] array) {
		ad.deleteBatcheVideo(array);
	}
	//删除视频
	@Override
	public void deleteIdVideo(Video vd) {
		ad.deleteIdVideo(vd);
	}
	//根据id查视频
	@Override
	public Video selectVideoById(Video vd) {
		return ad.selectVideoById(vd);
	}
	//修改视频
	@Override
	public void updateVideo(Video vd) {
		ad.updateVideo(vd);
	}
	//查询所有学科
	@Override
	public List<Subject> getAllSubject() {
		return ad.getAllSubject();
	}
	//添加课程
	@Override
	public void addCourse(Course cu) {
		ad.addCourse(cu);
	}
	//删除课程
	@Override
	public void deleteCourseById(Course cu) {
		ad.deleteCourseById(cu);
	}
	//根据id查课程
	@Override
	public Course selectCourseById(Course cu) {
		return ad.selectCourseById(cu);
	}
	//修改课程
	@Override
	public void updateCourse(Course cu) {
		ad.updateCourse(cu);
	}
	//添加主讲人
	@Override
	public void addSpeaker(Speaker sp) {
		ad.addSpeaker(sp);
	}
	//删除主讲人
	@Override
	public void deleteSpeakerById(Speaker sp) {
		ad.deleteSpeakerById(sp);
	}
	//根据id查主讲人
	@Override
	public Speaker selectSpeakerById(Speaker sp) {
		return ad.selectSpeakerById(sp);
	}
	//修改主讲人
	@Override
	public void updateSpeaker(Speaker sp) {
		ad.updateSpeaker(sp);
	}
	//动态查询视频
	@Override
	public List<Video> selectLikeVideo(VideoEx vd) {
		return ad.selectLikeVideo(vd);
	}
	//分页查询视频
	@Override
	public Map<String, Object> selectLimitVideo(Paging pg) {
		Map<String, Object> map=new HashMap<>();
		int countVideoById = ad.countVideoById(pg);
		List<Video> selectLimitVideo = ad.selectLimitVideo(pg);
		map.put("countVideo", countVideoById);
		map.put("vlist", selectLimitVideo);
		return map;
	}
	
	
	

}
